package com.itlong.cloud.controller.old;

import com.itlong.cloud.POJO.VO.smartcard.SmartCardOldLoginVO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.enumerate.oldapp.Code;
import com.itlong.cloud.enumerate.oldapp.Message;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.user.smartcard.ISmartCardOldUserInfoServiceClient;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <desc>
 *      旧一卡通的登录。
 * <desc/>
 *
 * @createDate 2017/11/1.
 */
@RestController
@RequestMapping("/sys/user")
public class SmartCardOldLoginController {


    @Autowired
    ISmartCardOldUserInfoServiceClient iSmartCardOldUserInfoServiceClient;

     /**
      * <desc>
      *      旧一卡通登录。
      * <desc/>
      *
      * @param  account 用户名或者手机号码
      * @param  pswd  密码
      * @return
      * @author shengen.T
      * @createDate 2017/11/2
      */
    @LoggerInfo(operateDesc = "旧一卡通登录")
    @ResponseBody
    @RequestMapping(path = "manage/login",method = RequestMethod.POST)
    public Message login(@RequestParam("account") String account, @RequestParam("pswd") String pswd){
       Message message;
       try {
           //判断账户和密码
           if(StringUtils.isEmpty(account) || StringUtils.isEmpty(pswd)){
               return new Message(Code.PARAM_ERR);
           }
           //判断账号和密码的真实性
           if((!account.equals(PlatformConstants.OLD_SMARTCARD_LOGIN_USER))||(!pswd.equals(PlatformConstants.OLD_SMARTCARD_LOGIN_PASSWORD))){
               return new Message(Code.ERROR);
           }
           SmartCardOldLoginVO voLogin = iSmartCardOldUserInfoServiceClient.login(account,pswd);
           message = new Message(Code.SUCCESS,voLogin);
       }catch (Exception e){
           throw new DataAccessException("【旧一卡通登录_login】用户登录失败", e);
       }
       return message;
    }
}
